﻿Module ModGeneral
    Public _IDPRODUCTO As Integer
    Public _IDUSUARIO As Integer
    Public _IDTAREA As Integer
    Public _IDAUTOBUS As Integer
    Public _IDCOMPRA As Integer
    Public _IDFAMILIA As Integer
    Public isProServ As Integer
    Public _Editar As Boolean
    Public _EnTarea As Boolean
    Public _EmpresaActiva As String


    'Objetos de TableAdapter, usados para las querys 
    Public pronom As New DataSet_Prod_ServTableAdapters.Productos_NombresTableAdapter
    Public producto As New DataSet_Prod_ServTableAdapters.ProductosTableAdapter
    Public max As New DataSet_Prod_ServTableAdapters.Max_MinTableAdapter
    Public propro As New DataSet_Prod_ServTableAdapters.Productos_ProveedorTableAdapter
    Public autobus As New DataSet_Prod_ServTableAdapters.AutobusesTableAdapter
    Public familia As New DataSet_Prod_ServTableAdapters.FamiliasTableAdapter

    'Objetos TableAdapters usados para bd local
    Public pronom_erp As New ERP_BDDataSetTableAdapters.Productos_NombresTableAdapter
    Public producto_erp As New ERP_BDDataSetTableAdapters.ProductosTableAdapter
    Public max_erp As New ERP_BDDataSetTableAdapters.Max_MinTableAdapter
    Public propro_erp As New ERP_BDDataSetTableAdapters.Productos_ProveedorTableAdapter
    Public tareas_erp As New ERP_BDDataSetTableAdapters.Tareas_PendientesTableAdapter

    Public Function EstadoRed() As Boolean
        Try
            If My.Computer.Network.IsAvailable() Then
                If My.Computer.Network.Ping("201.163.91.243", 3000) Then 'Asignamos la ip a verificar (SQL SERVER IP) y el tiempo de espera
                    EstadoRed = True
                Else
                    EstadoRed = False
                End If
            Else
                EstadoRed = False
            End If
        Catch ex As Exception
            EstadoRed = False
        End Try
    End Function

    Function NumeroDec(ByVal e As System.Windows.Forms.KeyPressEventArgs, ByVal Text As TextBox) As Integer

        Dim dig As Integer = Len(Text.Text & e.KeyChar)
        Dim a, esDecimal, NumDecimales As Integer
        Dim esDec As Boolean
        ' se verifica si es un digito o un punto 
        If Char.IsDigit(e.KeyChar) Or e.KeyChar = "." Then
            e.Handled = False
        ElseIf Char.IsControl(e.KeyChar) Then
            e.Handled = False
            Return a
        Else
            e.Handled = True
        End If
        ' se verifica que el primer digito ingresado no sea un punto al seleccionar
        If Text.SelectedText <> "" Then
            If e.KeyChar = "." Then
                e.Handled = True
                Return a
            End If
        End If
        If dig = 1 And e.KeyChar = "." Then
            e.Handled = True
            Return a
        End If
        'aqui se hace la verificacion cuando es seleccionado el valor del texto
        'y no sea considerado como la adicion de un digito mas al valor ya contenido en el textbox
        If Text.SelectedText = "" Then
            ' aqui se hace el for para controlar que el numero sea de dos digitos - contadose a partir del punto decimal.
            For a = 0 To dig - 1
                Dim car As String = CStr(Text.Text & e.KeyChar)
                If car.Substring(a, 1) = "." Then
                    esDecimal = esDecimal + 1
                    esDec = True
                End If
                If esDec = True Then
                    NumDecimales = NumDecimales + 1
                End If
                ' aqui se controla los digitos a partir del punto numdecimales = 4 si es de dos decimales 
                If NumDecimales >= 6 Or esDecimal >= 2 Then
                    e.Handled = True
                End If
            Next
        End If
        Return dig
    End Function

    Public Sub Sonido_notificacion()
        My.Computer.Audio.Play("Sonidos\triangle.wav")
    End Sub
End Module
